﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class GrouponTests
{
    [TestMethod]
    public void ShouldGetDailyDealWidget()
    {
        var html = Groupon.GetDailyDealWidget();

        Assert.IsNotNull(html);
    }

    [TestMethod]
    public void ShouldGetDivisionsShowDefaults()
    {
        Groupon.Initialize("6ce3f022ba130fe193f662bce49064ac6ed5bc21");

        var divisions = Groupon.GetDivisions(show: "default");

        Assert.IsNotNull(divisions);
        Assert.IsTrue(divisions.Count() > 0);
        Assert.IsNotNull(divisions.ElementAt(0).id);
        Assert.IsNotNull(divisions.ElementAt(0).name);
        Assert.IsNotNull(divisions.ElementAt(0).lat);
        Assert.IsNotNull(divisions.ElementAt(0).lng);
    }

    [TestMethod]
    public void ShouldGetDivisionsShowSelectedFields()
    {
        Groupon.Initialize("6ce3f022ba130fe193f662bce49064ac6ed5bc21");

        var divisions = Groupon.GetDivisions(show: "id,name");

        Assert.IsNotNull(divisions);
        Assert.IsTrue(divisions.Count() > 0);
        Assert.IsNotNull(divisions.ElementAt(0).id);
        Assert.IsNotNull(divisions.ElementAt(0).name);
    }

    [TestMethod]
    public void ShouldGetDealsForDivision()
    {
        Groupon.Initialize("6ce3f022ba130fe193f662bce49064ac6ed5bc21");

        var deals = Groupon.GetDeals(divisionId: "chicago");

        Assert.IsNotNull(deals);
        Assert.IsTrue(deals.Count() > 0);
        Assert.IsNotNull(deals.ElementAt(0).Id);
        Assert.AreEqual(deals.ElementAt(0).Division.Id, "chicago");
    }

    [TestMethod]
    public void ShouldGetDealsWithSpecificField()
    {
        Groupon.Initialize("6ce3f022ba130fe193f662bce49064ac6ed5bc21");

        var deals = Groupon.GetDeals(divisionId: "chicago", show: "options");

        Assert.IsNotNull(deals);
        Assert.IsTrue(deals.Count() > 0);
        Assert.IsNotNull(deals.ElementAt(0).Options);        
    }

    [TestMethod]
    public void ShouldGetDealsForLatitudeLongitude()
    {
        Groupon.Initialize("6ce3f022ba130fe193f662bce49064ac6ed5bc21");

        var deals = Groupon.GetDeals(latitude: "41.8795", longitude: "-87.6243");

        Assert.IsNotNull(deals);
        Assert.IsTrue(deals.Count() > 0);
        Assert.IsNotNull(deals.ElementAt(0).Id);
        Assert.AreEqual(deals.ElementAt(0).Division.Lat.ToString(), "41.8795");
        Assert.AreEqual(deals.ElementAt(0).Division.Lng.ToString(), "-87.6243");
    }

    [TestMethod]
    public void ShouldGetDeal()
    {
        Groupon.Initialize("6ce3f022ba130fe193f662bce49064ac6ed5bc21");

        var deal = Groupon.GetDeal("kodak-chicago");

        Assert.IsNotNull(deal);
        Assert.IsNotNull(deal.Title);
        Assert.AreEqual(deal.Id, "kodak-chicago");        
    }
}
